Java JavaScript Python C# C C++ Go Kotlin PHP Swift R Ruby TypeScript Scala SQL Perl rust VisualBasic Matlab Julia

Python Operators

Identity operators

Identity operators in Python are used to compare the objects, not if they are equal, but if they are actually the same object, with the same memory location. There are two types of identity operators in Python: is: This operator returns True if both variables are the same object (i.e., they are located at the same memory location), and False otherwise.
is - identity operator example in python x = 5 y = 5 print(x is y)

Output

True
is not: This operator returns True if both variables are not the same object (i.e., they are not located at the same memory location), and False otherwise.
is not identity operator example in python x = 5 y = 6 print(x is not y)

Output

True
Please note that the is and is not operators are different from the equality (==) and inequality (!=) operators, which compare the values of the variables, not their identities.

  📌TAGS

★python ★ operators ★ Identity

Tutorials